import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class TestInsert {


	public static void main(String[] args) throws Exception {
		Connection connection = DriverManager.getConnection("jdbc:mysql://192.168.10.187:30173/code", "root", "goldgov");
		Statement statement = connection.createStatement();

		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		
		long begin = System.currentTimeMillis();
		long totalSpend = 0;
		for (int i = 1; i <= 700000; i++) {
			String id = UUID.randomUUID().toString();
			String insertSql = "INSERT TEST_TABLE (TABLE_ID,TABLE_NAME,TABLE_INT,TABLE_DATE,TABLE_STRING ,TABLE_INT_2,TABLE_STRING2,TABLE_DATE_2 , TABLE_INT_3,TABLE_STRING_3,TABLE_DATE_3)" +
								"VALUES" + 
								"('" + id + "','TABLE_NAME_" + i +"'," + i +",NOW(),'TABLE_STRING_" + i + "' ," + (i+1) + ",'TABLE_STRING_" + i + "',NOW() , " + (i+2) + ",'TABLE_STRING_" + i +"',NOW())";
			statement.executeUpdate(insertSql);
			String insertSubSql = "INSERT TABLE_ORDER (ORDER_ID,ORDER_NUM,TABLE_ID)VALUES(uuid()," + (i+1) +",'" + id + "')";
			statement.executeUpdate(insertSubSql);
			if(i%200 == 0) {
				long pause = System.currentTimeMillis();
				long spend = (pause-begin);
				totalSpend += spend;
				System.out.println("[" + sdf.format(new Date()) + "] INSERTED " + i + " RECORDS.Spend time:" + spend + "ms");
				begin = System.currentTimeMillis();
			}
		}
		System.out.println("[" + sdf.format(new Date()) + "] COMPLETED!! Spend time:" + (totalSpend/60) + "s");
		statement.close();
		connection.close();
	}
}
